package com.ymttest.database.sqlwapper.sqdistributor;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.sqdistributor.DistributionAgencySubDistributorConfig;

public class DistributionAgencySubDistributorConfigWrapper {

	SqlManager manager;

	public DistributionAgencySubDistributorConfigWrapper() {
		manager = new SqlManager("sqdistributor");
	}

	@SuppressWarnings("unchecked")
	public DistributionAgencySubDistributorConfig selectByPrimaryKey(Long id) {

		DistributionAgencySubDistributorConfig distributionAgencySubDistributorConfig = null;
		List<DistributionAgencySubDistributorConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencySubDistributorConfigMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencySubDistributorConfig = result.get(0);
		}

		return distributionAgencySubDistributorConfig;
	}

	@SuppressWarnings("unchecked")
	public DistributionAgencySubDistributorConfig selectByMerchantIdAndDistributorType(
			Long merchantId, Integer distributorType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("merchant_id", merchantId);
		map.put("distributor_type", distributorType);

		DistributionAgencySubDistributorConfig distributionAgencySubDistributorConfig = null;
		List<DistributionAgencySubDistributorConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencySubDistributorConfigMapper.selectByMerchantIdAndDistributorType",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencySubDistributorConfig = result.get(0);
		}

		return distributionAgencySubDistributorConfig;
	}

	@SuppressWarnings("unchecked")
	public DistributionAgencySubDistributorConfig selectByMerchantIdAndDistributorId(
			Long merchantId, Long distributorId) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("merchant_id", merchantId);
		map.put("distributor_id", distributorId);

		DistributionAgencySubDistributorConfig distributionAgencySubDistributorConfig = null;
		List<DistributionAgencySubDistributorConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencySubDistributorConfigMapper.selectByMerchantIdAndDistributorId",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencySubDistributorConfig = result.get(0);
		}

		return distributionAgencySubDistributorConfig;
	}

	@SuppressWarnings("unchecked")
	public DistributionAgencySubDistributorConfig selectByMerchantIdAndDistributorIdAndType(
			Long merchantId, Long distributorId, Integer distributorType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("merchant_id", merchantId);
		map.put("distributor_id", distributorId);
		map.put("distributor_type", distributorType);

		DistributionAgencySubDistributorConfig distributionAgencySubDistributorConfig = null;
		List<DistributionAgencySubDistributorConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencySubDistributorConfigMapper.selectByMerchantIdAndDistributorIdAndType",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencySubDistributorConfig = result.get(0);
		}

		return distributionAgencySubDistributorConfig;
	}

	public static void main(String[] args) {

		DistributionAgencySubDistributorConfigWrapper test = new DistributionAgencySubDistributorConfigWrapper();

		System.out.println(test.selectByMerchantIdAndDistributorIdAndType(
				501576890L, 25912388L, 2).getDistributor_id());
	}
}
